package org.monkey.common.generator.service;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ClassLoaderUtil;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.monkey.common.generator.entity.GeneratorConfig;
import org.monkey.common.generator.entity.JavaEntityInfo;

public interface TemplateFileFormatter {

  String getTemplateStr();

  String getTemplateName();

  void format(File rootDir, List<JavaEntityInfo> javaEntityInfos, GeneratorConfig config);

  default String loadTemplateStr(String filename) {
    InputStream is = ClassLoaderUtil.getClassLoader().getResourceAsStream("org/monkey/common/generator/formatter/template/" + filename);
    try {
      return IoUtil.read(is, StandardCharsets.UTF_8);
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }



}
